home *** CD-ROM | disk | FTP | other *** search
- Path: hp.fciencias.unam.mx!usenet
- From: Ernesto <gsr@servidor.unam.mx>
- Newsgroups: comp.lang.c++
- Subject: Re: How do I overload 'char*' in my class. Is it possible?
- Date: 14 Feb 1996 07:35:43 GMT
- Organization: A poorly-installed InterNetNews site
- Message-ID: <4fs3cf$4a4@hp.fciencias.unam.mx>
- NNTP-Posting-Host: slip22.noc.unam.mx
-
- wawda@alcor.usc.edu (Abu Wawda) writes:
- > I wrote a string class and now I would like to overload: char*
- > (character pointer), but can't figure out how to do it. I've already
- > overloaded the +, +=, ==, =, and some operator operators, but can't
- > figure how to do this (or even if it's possible). Basically I want
- > something like:
- >
- > char* operator ?? ()
- >
- > so that my string class can also return char*. Please help. Thanks,
- >
- > Abu Wawda
- > wawda@scf.usc.edu
- >
-
- Try this:
-
- class String {
- public:
- //...
- operator const char* () const {return rep;}
- //...
- private:
- char *rep;
- };
-
- Maybe you should read the third chapter of the book "Advanced C++.
- Programming Styles and Idioms", by James O. Coplien, Addisson Wesley.
-
- Ernesto Silva
-